package simplest;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import util.ConnectionRabbitMQ;

/**
 * 消息发送者
 */
public class Sender {
    public static void main(String[] args) throws Exception {
        String msg = "oyz!!!  Hello,RibbitMq";
        // 1.获得连接
        Connection connection = ConnectionRabbitMQ.getConnection();
        // 2.在连接中创建通道
        Channel channel = connection.createChannel();
        // 3.创建消息队列(1,2,3,4,5)
        channel.queueDeclare("queue1",false,false,false,null);
        // 4.向指定的队列发送消息(1,2,3,4)
        channel.basicPublish("","queue1",null,msg.getBytes());
        System.out.println("发送:"+msg);
        // 5.释放资源
        channel.close();
        connection.close();
    }
}
